﻿using System;
using System.Collections.Generic;
using System.Text;
using OurSite.Business.Category;
using OurSite.Business.Helper;
using OurSite.Business.Picture;

namespace OurSite.Business.Event
{
    public class EventLight : BaseClass
    {
        protected List<EventLight> subEvents = new List<EventLight>();
        protected List<PictureLight> pictures = new List<PictureLight>();
        protected List<CategoryLight> categories = new List<CategoryLight>();

        public EventLight() {}

        public EventLight(Event evt)
        {
            Id = evt.Id;
            Name = evt.Name;
            ParentId = evt.ParentId;
            EventCode = evt.EventCode;
            ShortDescription = evt.ShortDescription;
            LongDescription = evt.LongDescription;
            Region = evt.Region;
            Country = evt.Country;
            State = evt.State;
            City = evt.City;
            Location = evt.Location;
            StartDate = evt.StartDate;
            EndDate = evt.EndDate;
            Order = evt.Order;
            Year = evt.Year;
            Month = evt.Month;
            Family = evt.Family;

            foreach (var pic in evt.Pictures)
            {
                Pictures.Add(new PictureLight(pic));
            }
            
            foreach (var sub in evt.SubEvents)
            {
                SubEvents.Add(new EventLight(sub));
            }

            foreach (var cat in evt.EventCategories)
            {
                Categories.Add(new CategoryLight(cat));
            }
        }

        public Guid ParentId { get; set; }
        public int EventCode { get; set; }
        public string ShortDescription { get; set; }
        public string LongDescription { get; set; }
        public string AlternateURL { get; set; }
        public string Region { get; set; }
        public string Country { get; set; }
        public string State { get; set; }
        public string City { get; set; }
        public string Location { get; set; }
        public DateTime StartDate { get; set; }
        public DateTime EndDate { get; set; }
        public int Order { get; set; }
        public int Year { get; set; }
        public int Month { get; set; }
        public List<EventLight> SubEvents
        {
            get { return subEvents; }
            set { subEvents = value; }
        }
        public string FacebookId { get; set; }
        public int Family { get; set; }
        public static string BuildImageBasePath(Event evt)
        {
            StringBuilder sbPath = new StringBuilder();
            sbPath.Append("Pictures/");
            sbPath.Append(evt.StartDate.Year + "/");
            sbPath.Append(evt.StartDate.ToString("MMMM") + "/");
            sbPath.Append(HelperUtilities.ReplaceSpecialCharacters(evt.Name) + "/");

            return sbPath.ToString();
        }
        public string DateRange
        {
            get
            {
                StringBuilder returnstring = new StringBuilder();
                returnstring.Append(StartDate.ToShortDateString());
                if (EndDate > DateTime.MinValue)
                    returnstring.Append(" to " + EndDate.ToShortDateString());

                return returnstring.ToString();
            }
        }
        public string FullLocation
        {
            get
            {
                StringBuilder returnstring = new StringBuilder();

                if (!string.IsNullOrEmpty(City))
                    returnstring.Append(City);

                if (!string.IsNullOrEmpty(State))
                    returnstring.Append(", " + State);

                if (!string.IsNullOrEmpty(Country))
                    returnstring.Append(", " + Country);

                return returnstring.ToString();
            }


        }
        public List<PictureLight> Pictures
        {
            get { return pictures; }
        }
        public List<CategoryLight> Categories
        {
            get { return categories; }
            set { categories = value; }
        }
    }


}
